<?php
class SupplierQuoteHelper {
	
	public static function getFuzzyList($where=null, $s=0, $l=0){
		list($part1, $part2) = self::fuzzyWhere($where);
		return Db::get('_supplier_quote')->select()->where($part1, $part2)->limit($s, $l)->getAll();
	}

	public static function fuzzyCount($where=null){
		list($part1, $part2) = self::fuzzyWhere($where);
		return Db::get('_supplier_quote')->count()->where($part1, $part2)->getCol();
	}

	protected static function fuzzyWhere($where){
		$tmp = array();
		if(isset($where['keyw'])){
			$keys = array('name', 'sno', 'brand', 'specific');
			foreach($keys as $k){
				$tmp[] = "`$k` LIKE '%". mysql_escape_string($where['keyw']) ."%'";
			}
			unset($where['keyw']);
		}
		return array($where, $tmp ? '('.join(' OR ', $tmp).')' : null );
	}

	public static function getList($where){
		return Db::get('SupplierQuote')->select()->where($where)->getAll();
	}

}
?>
